package android.slc.appbase.ui.activity.base;

import android.os.Bundle;
import android.slc.appbase.vm.AppBaseViewModel;
import android.slc.core.vm.BaseViewModel;
import android.slc.corelifecycle.ui.activity.FastRxMvvmActivity;
import android.slc.toolbar.ISlcToolBarDelegate;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.databinding.ViewDataBinding;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.callback.NavigationCallback;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;

public abstract class AppMvvmBaseActivity<V extends ViewDataBinding, VM extends AppBaseViewModel> extends FastRxMvvmActivity<V, VM> implements NavigationCallback {

    @Override
    public void onBindViewBefore() {
        super.onBindViewBefore();
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState) {
        super.onBindView(savedInstanceState);
        KeyboardUtils.fixAndroidBug5497(this);
    }

    @Override
    protected void onInitBarVm() {
        super.onInitBarVm();
        BarUtils.transparentStatusBar(this);
        mBarVm.setStatusBarLightMode(true);
    }

    @Override
    protected ISlcToolBarDelegate onInitSlcToolBarDelegate() {
        return null;
    }

    @Override
    protected void registerLiveEvent(BaseViewModel viewModel) {
        if (viewModel instanceof AppBaseViewModel) {
            AppBaseViewModel appBaseViewModel = (AppBaseViewModel) viewModel;
            appBaseViewModel.getStartActivityByARouterOf().observe(this, postcard -> postcard.navigation(AppMvvmBaseActivity.this));
        }
        super.registerLiveEvent(viewModel);
    }

    @Override
    public void onFound(Postcard postcard) {
        LogUtils.iTag("onFound", "已找到");
    }

    @Override
    public void onLost(Postcard postcard) {
        ToastUtils.showShort("未找到activity");
        LogUtils.iTag("onLost", "未找到");
    }

    @Override
    public void onArrival(Postcard postcard) {
        LogUtils.iTag("onArrival", "已到达");
    }

    @Override
    public void onInterrupt(Postcard postcard) {
        ToastUtils.showShort("被中断");
    }

}
